define([], function() {
	return {
		title: ['<a href="user.html">个人中心</a>', "摄影管理", "图片审核"],
		init: function(content) {
			let form = content.children("form");
			let table = content.children("table");
			let search = [];
			let picClass=[];
			let photoPicStatus = content.find("select[name='photoPicStatus']");
			let tatusIdTemplate = content.find("._statusIdTemplate");
			let actionEvent = {
					"click .photopicid": function(e, value, row) {
						loadimg(e, value, row);
						$('#photoPicDialog').modal();
					},
					"change .photoPicStatus": function(e, value, row) {
						changStatus(row.photoPicId, e.target.value);
					},
				};
			let tableInit = function() {
				table.bootstrapTable({
					url: 'photo/picture.do', // 表格数据来源
					method: "get",
					sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
					pageNumber: 1, //初始化加载第一页，默认第一页
					pageSize: 10, //每页的记录行数（*）
					pageList: [5, 10, 15, 20, 30, 50], //可供选择的每页的行数（*）
					pagination: true, //是否显示分页（*）
					dataField: "list",
					toolbar: form,
					queryParamsType: "",
					queryParams: function(p) {
						let ps = [].concat(search);
						ps.push({
							"name": "current",
							"value": p.pageNumber
						});
						ps.push({
							"name": "rowMax",
							"value": p.pageSize
						});
						ps.push({
							"name": "sortName",
							"value": p.sortName
						});
						ps.push({
							"name": "sortOrder",
							"value": p.sortOrder
						});
						return ps;
					},
					columns: [{
							field: 'photoPicClassId',
							title: '类别',
							sortable: true,
							sortName: "PHOTO_PIC_CLASS_ID",
							width: 20,
							formatter: function(value, row, index, field) {
								return picClass[value];
							}
						}, {
							field: 'photoReleaseTime',
							title: '上传时间',
							sortable: true,
							sortName: "PHOTO_RELEASE_TIME",
							align: "center",
							width: 30
						}, {
							field: 'photoWriterId',
							title: '作者账号',
							sortable: true,
							sortName: "PHOTO_WRITER_ID",
							width: 30
						}, {
							field: 'photoPicTitle',
							title: '相册集名',
							sortable: true,
							sortName: "PHOTO_PIC_TITLE",
							width: 40,
						}, {
							field: 'photoPicStatus',
							title: '状态',
							sortName: "PHOTO_PIC_STATUS",
							align: "center",
							width: 70,
							events: actionEvent,
							formatter: function(value, row, index, field) {
								let s = tatusIdTemplate.children("select");
								s.children().removeAttr("selected").filter("[value='" + value + "']").attr("selected", "selected");
								return tatusIdTemplate.html();
							}
						},{
							field: 'photoPicId',
							align: "center",
							title: '查看详情',
							align: "center",
							width: 100,
							events: actionEvent,
							formatter: function(value, row, index, field) {
								return '<a class="photopicid" href="javascript:void(0);">查看原图</a>';
							}
						}
					]
				});
			};
			form.on("submit", function() {
				search = form.serializeArray();
				table.bootstrapTable('refresh');
				return false;
			});
			$("<option></option>").val(1).text("未审批").appendTo(photoPicStatus);
			$("<option></option>").val(2).text("未通过").attr("selected", "selected").appendTo(photoPicStatus);
			$("<option></option>").val(3).text("已通过").appendTo(photoPicStatus);
			$("<option></option>").val(4).text("已下架").appendTo(photoPicStatus);

			tatusIdTemplate.children("select").clone().attr("id", "select-change").appendTo($(".select-show"));
			
			$.get(
				"photo/picType.do",
				function(data) {
					$.each(data, function(i, v) {
						picClass[v.photoPicClassId] = v.photoPicClassName;
					});
				},"json"
			);
			/**
			 * 初始查询状态为未审批
			 */
			$(form).trigger("submit");
			
			tableInit();
			/**
			 * 查看原图
			 * @param {Object} e
			 * @param {Object} value
			 * @param {Object} row
			 */
			let loadimg = function(e, value, row){
				$("#photoPic").attr("src", row.photoOriginalPicPath);
				$(".select-show")
				.find("select")
				.children().removeAttr("selected")
				.filter("[value='" + row.photoPicStatus + "']")
				.attr("selected", "selected");
				sessionStorage.photopicid = row.photoPicId;
			}
			
			$("body").on("change", "#select-change", function(e){
				changStatus(sessionStorage.photopicid, e.target.value);
			});
			/**
			 * 修改状态
			 * @param {Object} id
			 * @param {Object} status
			 */
			let changStatus = function(id, status){
				$.get(
					"photo/uploade-status.do",{
						photoPicId:id,
						status:status
					},function(data){
						if(data.ok) {
							toastr.success("修改状态成功");
						} else {
							toastr.error("修改状态失败：" + data.message);
						}
					},"json"
				);
			}
		}
	}
});